<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* 
      finally方法:
        - 无论调用finally方法的promise实例是成功还是失败,都能进入finally的回调函数中执行
        - finally不接受promise实例的值
        - finally的返回值
          - 默认穿透(finally的返回值和调用finally的promise实例保持一致)
          - 当finally的回调函数返回一个失败的promise实例时,finally的返回值和这个失败的promise实例保持一致
          - 当finally的回调函数中报错,则finally返回失败的promise实例,值为错误信息
    */

    const p1 = new Promise((resolve,reject)=>{
      console.log("请求数据a...");
      try{
        // throw new Error("网络错误~~~")
        setTimeout(()=>{
          console.log("数据a请求成功!!!");
          resolve("数据a请求成功!!!")
        },2000)
      }catch(e){
        reject(e.message)
      }
    })
    console.log("p1",p1);

    const p2 = p1.finally((reason)=>{
      console.log(reason);
      
      return new Promise((resolve,reject)=>{
        // resolve(1)
        reject(2)
      })
      
      throw new Error("finally报错")
    })
    console.log("p2",p2);

    </script>
</body>
</html>